home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / GRAPHICS.SWG / 0075_Another Bezier Curve.pas < prev    next >
Pascal/Delphi Source File  |  1994-02-03  |  1KB  |  52 lines

  1. {
  2. From: NICK ONOUFRIOU
  3. Subj: RIP Bezier Curves
  4. ---------------------------------------------------------------------------
  5. SP> I can't post the code I have that IS Telegrafix-compatible (for obvious
  6. SP> reasons) but if you post your code I can try and modify it to make it
  7. SP> work correctly.
  8.  
  9. Here it is. It comes close, but can't get it to create the same curves that
  10. Telegrafix creates. Thanks for any help Sean. Are you writing the RIP code
  11. for TELIX?
  12. }
  13.  
  14. procedure DrawBezierCurve(px1,py1,px2,py2,px3,py3,px4,py4,count : integer);
  15.  
  16. function pow(x : real; y : word) : real;
  17. var
  18.   nt     : word;
  19.   result : real;
  20. begin
  21.  result := 1;
  22.  for nt := 1 to y do
  23.      result := result * x;
  24.  pow := result;
  25. end;
  26.  
  27. procedure Bezier(t : real; var x, y : integer);
  28. begin
  29.  x := round(pow(1 - t, 3) * px1 + 3 * t * pow(1 - t, 2) * px2 +
  30.                 3 * t * t * (1 - t) * px3 + pow(t, 3) * px4);
  31.  y := round(pow(1 - t, 3) * py1 + 3 * t * pow(1 - t, 2) * py2 +
  32.                 3 * t * t * (1 - t) * py3 + pow(t, 3) * py4);
  33. end;
  34.  
  35. var
  36.  resolution,t : real;
  37.  xc, yc       : integer;
  38. begin
  39.         if count = 0 then exit;
  40.         resolution:=1/count;
  41.  
  42.         Moveto(px1,py1);
  43.         t := 0;
  44.         while t < 1 do begin
  45.            Bezier(t, xc, yc);
  46.            lineto(xc, yc);
  47.            t := t + resolution;
  48.         end;
  49.         LineTo(px4,py4);
  50. end;
  51.  
  52.